package Stragos.servlet.local;

import java.io.IOException;
//import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Stragos.excepcion.DAOExcepcion;
import Stragos.modelo.Local;
import Stragos.negocio.GestionLocal;


@WebServlet("/LocalInsertarServlet")
public class LocalInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public LocalInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String nombre = request.getParameter("nombre");
		String direccion = request.getParameter("direccion");
		String telefono = request.getParameter("telefono");
		String correo = request.getParameter("correo");
		String descripcion = request.getParameter("descripcion");
		
		Local lo = new Local();
		lo.setNombre(nombre);
		lo.setDireccion(direccion);
		lo.setTelefono(telefono);
		lo.setCorreo(correo);
		lo.setDescripcion(descripcion);
		
		
		
		GestionLocal negocio = new GestionLocal();
		try {
			negocio.insertar(nombre, direccion, descripcion, telefono, correo );
			response.sendRedirect(request.getContextPath()	+ "/LocalBuscarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}
}